//
//  ViewController.m
//  Calendar
//
//  Created by 王文娟 on 16/7/13.
//  Copyright © 2016年 EJU. All rights reserved.
//

#import "ViewController.h"
#import "SOChooseDateHeader.h"
#import "SOCalendar.h"
@interface ViewController ()<SOCalendarDelegate,SOChooseDateHeaderDelegate>

@property (nonatomic, weak) SOChooseDateHeader *header;

@property (nonatomic, weak) SOCalendar *calendar;
@end

@implementation ViewController

- (void)viewDidLoad {
    
    [super viewDidLoad];
    
    SOChooseDateHeader *header = [[SOChooseDateHeader alloc]initWithFrame:(CGRect){0,20,self.view.frame.size.width,60}];
    
    header.deledate = self;
    
    _header = header;
    
    [self.view addSubview:header];
    
    SOCalendar *calendar = [[SOCalendar alloc]initWithFrame:(CGRect){0,80,self.view.frame.size.width,self.view.frame.size.height-80}];
    
    _calendar = calendar;
    
    calendar.delegate = self;
    
//    calendar.visibleYear = ^(NSInteger visibleYear){
//    
//        header.yearText = [NSString stringWithFormat:@"%zd%@",visibleYear,@"年"];
//    
//    };
    
    [self.view addSubview:calendar];
    
    [calendar reloadData];
    
    
}

#pragma mark - SOCalendarDelegate

-(void)calendar:(SOCalendar *)calendar didShowYear:(NSInteger)visibleYear{

    self.header.yearText = [NSString stringWithFormat:@"%zd%@",visibleYear,@"年"];
}

-(void)calendar:(SOCalendar *)calendar didSelectDate:(NSDate *)date{
    
    NSLog(@"%@",[date descriptionWithLocale:@"zh_CN"]);

}

#pragma mark - SOChooseDateHeaderDelegate
-(void)didClickTodayInChooseDateHeader:(SOChooseDateHeader *)chooseDateHeader{
    
    [self.calendar scrollToDate:[NSDate date]];

}

@end
